package com.qf.lanzhou.shop.pojo.vo;

import lombok.Data;

/**
 * @author jack
 * 成功状态码数:100 失败状态码:200  未登录状态码:300
 */
@Data
public class BaseRespVO<T> {
    private int code = CodeType.SUCCESS.getValue();
    private String msg;
    private T data;

    public enum CodeType {
        //状态码
        SUCCESS(100), FAILED(200), UN_LOGIN(300);
        private int value;

        CodeType(int value) {
            this.value = value;
        }

        public int getValue() {
            return value;
        }
    }

    private static BaseRespVO instance;

    public static BaseRespVO getInstance() {
        return instance;
    }

    //成功标准返回
    public BaseRespVO success(T data) {
        BaseRespVO result = new BaseRespVO();
        result.setData(data);
        return result;
    }

    //失败标准返回
    public BaseRespVO failed(String msg) {
        BaseRespVO result = new BaseRespVO();
        result.setCode(CodeType.FAILED.getValue());
        result.setMsg(msg);
        return result;
    }

    //未登录状态码返回
    public BaseRespVO UN_LOGIN(String msg) {
        BaseRespVO result = new BaseRespVO();
        result.setCode(CodeType.FAILED.getValue());
        result.setMsg(msg);
        return result;
    }
}
